import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class point{
    public int num;
    public int x;
    public int y;
}
public class demo01 {
    //bfs(广度优先搜索)
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int[][] arr=new int[n][m];
        int[] dx={0,1,0,-1};
        int[] dy={1,0,-1,0};
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                arr[i][j]=sc.nextInt();
            }
        }
        int x1=sc.nextInt();
        int y1=sc.nextInt();
        point p=new point();
        Queue<point> queue=new LinkedList<>();
        p.x=0;
        p.y=0;
        p.num=0;
        queue.offer(p);
        arr[0][0]=2;
        while (!queue.isEmpty()){
            int i=queue.peek().x;
            int j=queue.peek().y;
            if(i==x1&&j==y1){
                System.out.println(queue.peek().num);
                return;
            }
            for (int k = 0; k < 4; k++) {
                int i1=i+dx[k];
                int j1=j+dy[k];
                if((i1>=0&&i1<n)&&(j1>=0&&j1<m)&&(arr[i1][j1]==0)){
                    point tmp=new point();
                    tmp.x=i1;
                    tmp.y=j1;
                    tmp.num=queue.peek().num+1;
                    queue.offer(tmp);
                    arr[i1][j1]=2;
                }
            }
            queue.poll();
        }
    }
}
//5 4
//0 0 1 0
//0 0 0 0
//0 0 1 0
//0 1 0 0
//0 0 0 1
//3 2
